﻿using System;
using System.Web.UI;
using System.Web.Configuration;
using System.Data;
using System.Web.UI.WebControls;

public partial class manager_temt_SetTmp : System.Web.UI.Page
{
    public string Html_Dept = "";
    public string Html_Dept_Detail = "";
    DBHelper db = new DBHelper(WebConfigurationManager.ConnectionStrings["connString"].ConnectionString);
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetDept();
            loadData();
        }
    }

    private void GetDept()
    {
        int i = 0;
        Html_Dept = "";
        DataTable dt = db.getList("select * from dict_dept where [isUsing]=1 order by id");
        foreach (DataRow dr in dt.Rows)
        {
            if (i == 0)
            {
                Html_Dept += "<li onclick=\"SetDept('" + dr["id"].ToString() + "','" + dr["mc"].ToString() + "')\" role=\"presentation\" class=\"active\"><a href=\"#dept_" + dr["id"].ToString() + "\" role=\"tab\" data-toggle=\"tab\">" + dr["mc"].ToString() + "</a></li>";
            }
            else
            {
                Html_Dept += "<li onclick=\"SetDept('" + dr["id"].ToString() + "','" + dr["mc"].ToString() + "')\"  role=\"presentation\"><a href=\"#dept_" + dr["id"].ToString() + "\" role=\"tab\" data-toggle=\"tab\">" + dr["mc"].ToString() + "</a></li>";
            }
            i = 1;
        }
    }

    private void loadData()
    {
        dept_id.Value = "";
        int i = 0;
        DataTable dt = db.getList("select * from dict_dept where [isUsing]=1 order by id");
        foreach (DataRow dr in dt.Rows)
        {
            dept_id.Value = dept_id.Value + "|" + dr["id"].ToString();
            if (i == 0)
            { Html_Dept_Detail += "<div role=\"tabpanel\" class=\"tab-pane active\" id=\"dept_" + dr["id"].ToString() + "\">"; }
            else
            { Html_Dept_Detail += "<div role=\"tabpanel\" class=\"tab-pane\" id=\"dept_" + dr["id"].ToString() + "\">"; }

            Html_Dept_Detail += "<div class=\"box-body\">";
            Html_Dept_Detail += "<table id=\"table_" + dr["id"].ToString() + "\" class=\"table table-bordered table-striped\">";
            Html_Dept_Detail += "<thead>";
            Html_Dept_Detail += "<tr>";
            Html_Dept_Detail += "<th></th>";
            Html_Dept_Detail += "<th class=\"col-sm-2\">名称</th>";
            Html_Dept_Detail += "<th class=\"col-sm-1\">类型</th>";
            Html_Dept_Detail += "<th class=\"col-sm-1\">当前在岗</th>";
            Html_Dept_Detail += "<th class=\"col-sm-6\">模板使用</th>";
            Html_Dept_Detail += "<th class=\"col-sm-1\">操作</th>";
            Html_Dept_Detail += "</tr>";
            Html_Dept_Detail += "</thead>";
            Html_Dept_Detail += "<tbody>";
            DataTable dt1 = db.getList("v_dict_dept_position", "*", "dept=" + dr["id"].ToString(), "bh");
            foreach (DataRow dr1 in dt1.Rows)
            {
                Html_Dept_Detail += "<asp:Repeater runat=\"server\">";
                Html_Dept_Detail += "<ItemTemplate>";
                Html_Dept_Detail += "<tr>";
                Html_Dept_Detail += "<td>" + dr1["id"].ToString() + "</td>";
                switch (dr1["type"].ToString())
                {
                    case "1":
                        Html_Dept_Detail += "<td><b>" + dr1["mc"].ToString() + "</b></td>";
                        Html_Dept_Detail += "<td>" + SQ_Eval_Pub.GetPsType(dr1["type"].ToString()) + "</td>";
                        break;
                    case "2":
                        Html_Dept_Detail += "<td style=\"padding-left:30px;\">" + dr1["mc"].ToString() + "</td>";
                        Html_Dept_Detail += "<td style=\"padding-left:15px;\">" + SQ_Eval_Pub.GetPsType(dr1["type"].ToString()) + "</td>";
                        break;
                    case "3":
                        Html_Dept_Detail += "<td style=\"padding-left:50px;\">" + dr1["mc"].ToString() + "</td>";
                        Html_Dept_Detail += "<td style=\"padding-left:25px;\">" + SQ_Eval_Pub.GetPsType(dr1["type"].ToString()) + "</td>";
                        break;
                }



                Html_Dept_Detail += "<td>" + dr1["userName"].ToString() + "</td>";
                Html_Dept_Detail += "<td><b>" + dr1["evalmc"].ToString() + "</b></td>";
                Html_Dept_Detail += "<td><a data-toggle=\"modal\" data-target=\"#userManager\" data-action=\"update\" data-bid=\"" + dr1["id"].ToString() + "\">修改</a></td>";
                Html_Dept_Detail += "</tr>";
            }
            Html_Dept_Detail += "</tbody>";
            Html_Dept_Detail += "</table>";
            Html_Dept_Detail += "</div>";
            Html_Dept_Detail += "</div>";
            i = 1;
        }



        DataTable dtType = db.getList("[v_dict_dept_position_evaluate]", "ID,('['+typemc+'] '+mc) as mc1", "isUsing=1", "id desc");
        dllEval.DataSource = dtType;
        dllEval.DataTextField = "mc1";
        dllEval.DataValueField = "ID";
        dllEval.DataBind();
        dllEval.Items.Insert(0, new ListItem("-无-", "0"));




    }


    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        string errmsg = "";
        string id = hidBID.Value;
        string evalid = dllEval.SelectedValue;

        string sql = "update dict_dept_position set  evalid='" + evalid + "' where id=" + id;

        int i = db.executeNoneQuery(sql, ref errmsg);
        if (i > 0)
        {
            Response.Write(CommonHelper.alertMsgAndRedirect("设置成功", Request.Url.LocalPath + Request.Url.Query));
        }
        else
        {
            Response.Write(CommonHelper.alertMsg("设置失败," + errmsg));
        }

    }

    protected void btnGet_Click(object sender, EventArgs e)
    {
        DataTable Dt = db.getList("[v_dict_dept_position]", "*", "id=" + hidBID.Value, "id");
        if (Dt.Rows.Count == 1)
        {
            dllEval.SelectedValue = Dt.Rows[0]["evalid"].ToString();
        }
    }

}